package game;

import behaviors.Rotation;
import engine.hw.Pointer;
import engine.hw.RunTimer;
import math.Maths;

public class ViewRotationMouse
{
    
    
    
    public ViewRotationMouse()
    {
        
    }
    
    public void update(Rotation viewRot)
    {
        float dXRot = (
            RunTimer.get().getFrameTime() * 
            Pointer.get().getMouseDY() * 
            Pointer.get().getSensitivityY()
        );
        float dYRot = (
            RunTimer.get().getFrameTime() * 
            Pointer.get().getMouseDX() * 
            Pointer.get().getSensitivityX()
        );
        
        viewRot.updateRots(dXRot, dYRot);
        this.limitCameraRotationX(viewRot);
    }
    
    private void limitCameraRotationX(Rotation viewRot)
    {
        float rotX = viewRot.getRots().x;
        if (rotX > Maths.PI_OVER_2 && rotX < Maths.PI)
        {
            float correctionX = Maths.PI_OVER_2 - rotX;
            viewRot.updateRots(correctionX, 0.0f);
        }
        else if (rotX <= Maths.PI_TIMES_3_OVER_2 && rotX >= Maths.PI)
        {
            float correctionX = Maths.PI_TIMES_3_OVER_2 - rotX;
            viewRot.updateRots(correctionX, 0.0f);
        }
    }

    public void destroy()
    {
        
    }
    
}
